import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by 14229 on 2020/2/19.
 */
public class Test06 {
    public static void main(String[] args) {

        Map<Character,Integer> map = new HashMap<>();
        char[] arr = {'a','a','b','a','n','a','a','b'};
        for (char s : arr) {
            Integer count = map.get(s);
            if (s!='a'){
                if (count==null){
                    count=1;
                }else {
                    count++;
                }
                map.put(s,count);
            }
        }

        StringBuilder sb = new StringBuilder();
        for (Character s : map.keySet()) {
            sb.append(s);
            sb.append(map.get(s));
        }
        char[] brr = new char[sb.length()];
        int count = 0;
        char[] chars = sb.toString().toCharArray();
        for (char aChar : chars) {
            brr[count++] = aChar;
        }
        System.out.println(Arrays.toString(brr));
    }
}
